#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

int n, k;
int a[N];

void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int w, t; cin >> w >> t;
        a[i] = t + k - w;
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n;i++) a[i] = max(a[i], a[i - 1] + 1);
    cout << a[n] << '\n';
}

signed main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


